package cn.usbtg.common.idmanager.formater;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间戳格式化器：
 * 获取指定格式的时间戳
 */
public class TimestrampFormater extends BasicFormater {
    public static final String FORMAT_PATTERN_YEAR = "yyyy";
    public static final String FORMAT_PATTERN_MONTH = "MM";
    public static final String FORMAT_PATTERN_DAY = "dd";
    public static final String FORMAT_PATTERN_HOUR = "HH";
    public static final String FORMAT_PATTERN_MINUTE = "mm";
    public static final String FORMAT_PATTERN_SECOND = "ss";
    public static final String FORMAT_PATTERN_MILLISECOND = "SSS";
    public static final String FORMAT_PATTERN_DATE = "yyyyMMdd";
    public static final String FORMAT_PATTERN_TIME = "HHmmss";
    public static final String FORMAT_PATTERN_DATETIME = "yyyyMMddHHmmss";
    public static final String FORMAT_PATTERN_TIMESTAMP = "yyyyMMddHHmmssSSS";

    protected Date sysDate;
    protected String formatPattern;

    public TimestrampFormater(String formatPattern) {
        this.formatPattern = formatPattern;
    }

    public TimestrampFormater(String... patterns) {
        StringBuilder sbPattern = new StringBuilder();
        for (String pattern : patterns) {
            sbPattern.append(pattern);
        }
        this.formatPattern = sbPattern.toString();
    }

    @Override
    public String next(Object... params) {
        sysDate = new Date();
        return last = new SimpleDateFormat(formatPattern).format(sysDate);
    }

    public Date getSysDate() {
        return sysDate;
    }

    public void setSysDate(Date sysDate) {
        this.sysDate = sysDate;
    }

    public String getFormatPattern() {
        return formatPattern;
    }

    public void setFormatPattern(String formatPattern) {
        this.formatPattern = formatPattern;
    }
}